/* ---------------------------------------------------------------------------------------------
 *
 *            Capital Alliance Software Confidential Proprietary 
 *            (c) Copyright CAS 201{x}, All Rights Reserved
 *                          www.pekall.com
 *
 * ----------------------------------------------------------------------------------------------
 */
package com.pekall.todo.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;

public class ToDoSQLHelper extends SQLiteOpenHelper {

	public static final String SID = "_id";
	public static final String TITLE = "title";
	public static final String ALARM = "alarm";
	public static final String STATE = "state";
	public static final String BEGIN = "begin";
	public static final String OVER = "over";
	public static final String PRIORITY = "priority";
	public static final String NOTES = "notes";
	public static final String REMINDER = "reminder";
	public static final String CREATED = "created";
	public static final String MODIFIED = "modified";
	public static final String TYPE = "type";
	
	public final static String DB_NAME = "todolist.db";
	public final static String TABLE_NAME = "todo_tasks";
	public final static int DB_VERSION = 1;

	public static final String AUTHORITY = "com.pekall.todolist";//content://com.pekall.todolist/todo_tasks
	public static final int ITEM = 1;
	public static final int ITEM_ID = 2;
	public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.pekall.todo.util.dir";
	public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.pekall.todo.util.item";
	public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY
			+ "/todo_tasks");
	private SQLiteDatabase db;

	public ToDoSQLHelper(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
		open(context);
	}

	public void onCreate(SQLiteDatabase db) {
		this.db = db;
		String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " ("
				+ "_id INTEGER PRIMARY KEY AUTOINCREMENT,"
				+ "title TEXT COLLATE LOCALIZED,state INTEGER,"
				+ "alarm INTEGER," + "begin INTEGER," + "over INTEGER,"
				+ "priority INTEGER," + "notes TEXT," + "reminder INTEGER,"
				+ "created INTEGER," + "modified INTEGER," + "type INTEGER);";
		db.execSQL(sql);
	}
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
	}
	public void open(Context context) {
		if (null == db || !this.db.isOpen()) {
			this.db = context.openOrCreateDatabase(DB_NAME,
					Context.MODE_PRIVATE, null);
		}
	}
}